*************************************************************************************
* Figure 1
*************************************************************************************

use  "Data_temp/turnout.dta", clear

* Generate election dummies
tab election, gen(elec_dummy)
forvalues x = 1/6 {
	dis `x'
	tab election if inrange(age`x',-24,23)
	}
	
* Create globals such that correct dummies are used per electoral cycle	
global elec4		elec_dummy2-elec_dummy6
global elec5		elec_dummy1 elec_dummy3-elec_dummy6
global elec6		elec_dummy1-elec_dummy2 elec_dummy4-elec_dummy6

snapshot erase _all
snapshot save

* Create basic program to produce graphs
cap program drop  elec

program def elec

	snapshot restore 1

	collapse (mean) voted (count) counter=voted if inrange(age`1',-24,24), by(age`1')
	
	twoway (scatter voted age`1' if age`1'<0, color(edkblue) ///
		msymbol(Oh) msize(medlarge)) ///
	(lfit voted age`1' if age`1'<0, color(edkblue) msymbol(Oh)) ///
	(scatter voted age`1' if age`1'>0, color(edkblue) mlwidth(medthick) ///
		msymbol(Oh) msize(medlarge)) ///
	(lfit voted age`1' if age`1'>0, color(edkblue) mlwidth(medthick) ///
		msymbol(Oh)), ///
	yt("Share voted", size(medlarge)) yl(0(0.2)1) ///
	xt("Relative age in months to cut-off") xl(-24(6)24) ////
	xline(0, lcolor(gs12)) ///
	legend(off) graphregion(margin(zero)) xt(, size(medlarge)) 
	
	
	graph export "Figures/fg1_`2'.eps", replace

end


*		* election cycle	* file name
elec	0					a	
elec	1					b
elec	2					c
elec	3					d